package MonteCarloSingleThreaded;

public class MonteCarloSingleThreaded {
	
	public static double MonteCarloStandardOption (String callPutFlag, double S, 
			double X, double T, double r, double b, 
			double v, int nSteps, int nSimulations)
	{
		java.util.Random random = new java.util.Random();

		double dt, St;
		double Sum = 0.0, Drift, vSqrdt;
		int z;

		dt 		= T / nSteps;
		Drift	= (b - v*v / 2) * dt;
		vSqrdt  = v * java.lang.Math.sqrt(dt);

		if(callPutFlag.equals("c"))
			z = 1;
		else if(callPutFlag.equals("p"))
			z = -1;
		else
			return -1;

		for ( int i=0 ; i<nSimulations ; i++ )
		{
			St = S;

			for ( int j=0 ; j < nSteps ; j++)
			{
				St = St * java.lang.Math.exp(Drift + vSqrdt * random.nextGaussian());
			}

			Sum = Sum + Math.max(z * (St - X), 0);
		}
		return java.lang.Math.exp(-r * T) * (Sum / nSimulations);
	}

}
